const crypto = require('crypto');

module.exports = ctx => {
  class Local {
    createNonceStr() {
      return Math.random().toString(36).substr(2, 15);
    }
    createTimestamp() {
      return '' + Date.now();
    }
    calcSignature({ options, join = '', hash = 'sha1' }) {
      const hashsum = crypto.createHash(hash);
      hashsum.update(options.join(join));
      return hashsum.digest('hex');
    }
    symmetricDifference(setA, setB) {
      const _difference = new Set(setA);
      for (const elem of setB) {
        if (_difference.has(elem)) {
          _difference.delete(elem);
        } else {
          _difference.add(elem);
        }
      }
      return _difference;
    }
  }
  return Local;
};
